Add support for browser platform#2975
Conversation
|
Thank you for opening this! We'll work on getting it reviewed. One thing I can say is that the |
| if (RuntimeInformation.IsOSPlatform(OSPlatform.Create("Browser"))) | ||
| { | ||
| // For WebAssembly, we need to pass the auth token as a query parameter | ||
| uri += $"&token={Uri.EscapeDataString(auth)}"; |
There was a problem hiding this comment.
It's generally not considered best practice to send an auth token via a URL param. To get around this in our C# (WebGL) and Typescript SDKs we generate a short-lived token which you can generate via an API call. This short lived token is then used instead of your real token. You can see an implementation of this here: (C# SDK) https://github.com/clockworklabs/SpacetimeDB/pull/2988/files and then also here for the typescript SDK: https://github.com/clockworklabs/SpacetimeDB/blob/36f7ca2583a7491285460454839e41ff43ec27a7/sdks/typescript/packages/sdk/src/websocket_decompress_adapter.ts#L93C1-L110C6
I think let's wait for #2988 to land first and see if we can just use the same auth flow that we're using for WebGL?
|
@rekhoff Testing requirements for this:
Impl requirements:
|
|
Changes in 461e245 break all Unity projects, including BitCraft. Without maintaing support for Unity projects, this PR can not move forward. |
|
@alex47 Thank you for your contribution!
If you're able to fix those issues we'll give this another review, |
|
Thanks again for the contribution, we haven't heard back in a while so we're going to close this for now but if you end up wanting to move this forward let us know 👍 |
Description of Changes
This is a continuation of:
browserplatform com.clockworklabs.spacetimedbsdk#274I have applied those changes to the latest codebase.
Added support for the browser platform.
This required:
Thread.Startwith aTask(Thread.Startis not supported forbrowserplatforms)PreProcessMessagesasync, in order to use Channels async methodsTaskto be allowed to run on a separate thread (ConfigureAwait(false))BlockingCollection(which is not supported on thebrowserplatform) withChannel(which is supported on all platforms)IDbConnection.Connectto run on any thread, not necessarily the caller (ConfigureAwait(false))Ws.Options.UseDefaultCredentials = true;(this is alreadytrueby default. In addition, using this setter is not being supported bybrowserplatforms.)Ws.Options.SetRequestHeaderis not supported onbrowserplatformAPI
N/A. No changes to the API.
Requires SpacetimeDB PRs
N/A
Testsuite
SpacetimeDB branch name: master
Testing
Testing was performed manually inside of a Blazor WebAssembly Standalone App, using the reference quickstart-chat code.
The test project can be found here: https://github.com/alex47/BlazorWebassemblyChat